package com.sphere.freereader.adapter;

/**
 * Created by aquarius on 2016/9/4.
 */

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sphere.freereader.R;
import com.sphere.freereader.entity.MenuPopupItem;

import java.util.List;

/**
 * popup菜单的适配器
 */
public class MenuPopupAdapter extends BaseAdapter {
    private Context context;
    private List<MenuPopupItem> list;

    public MenuPopupAdapter(Context context, List<MenuPopupItem> list) {
        super();
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MenuViewHolder holder = null;
        if (convertView == null) {
            holder = new MenuViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_menu_popup, parent, false);
            TextView textView = (TextView) convertView.findViewById(R.id.tv_menu_title);
            holder.title = textView;
            convertView.setTag(holder);
        } else {
            holder = (MenuViewHolder) convertView.getTag();
        }
        MenuPopupItem item = list.get(position);

        String title = item.getTitle();

        holder.title.setText(title);
        return convertView;
    }

    final class MenuViewHolder {
        TextView title;
    }

}
